using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour
{
    public static GameManager Instance;
    public enum GameStatusType { Ready,ingaming,Gameover,Completed}
    private GameStatusType gameStatus;
    public GameStatusType GameStatus
    {
        get
        {
            return gameStatus;
        }           
        set
        {
            gameStatus = value;
            switch (gameStatus)
            {
                
                case GameStatusType.Gameover:
                    EndGameView.Instance.OnShowGameOverView();
                    break;
                case GameStatusType.ingaming:
                    if (isCompletedGuideLevel)
                    {
                        GameObject[] emptyboxs = GameObject.FindGameObjectsWithTag("EmptyBox");
                        itemMax = emptyboxs.Length;
                    }
                    break;
                case GameStatusType.Completed:
                    EndGameView.Instance.OnShowCompletedView();
                    break;
                     
            }
        }
    }
    [SerializeField] public bool isCompletedGuideLevel;
    [SerializeField] GameObject guideLevel;
    [SerializeField] GameObject dailyLevel;
    [SerializeField] public int itemMax;
    [SerializeField] public int mergeItemCount;
    [SerializeField] GameObject btn;
    private void Awake()
    {
        Instance = this;
    }
    void Start()
    {
        isCompletedGuideLevel = false;
    }
    void Update()
    {
        Debug.Log("GameStatus:" + GameStatus);
        GameObject[] emptyBoxs = GameObject.FindGameObjectsWithTag("EmptyBox");
        if(emptyBoxs.Length == 0 )
        {
            if (!isCompletedGuideLevel)
            {
                isCompletedGuideLevel=true;
                guideLevel.SetActive(false);
                dailyLevel.SetActive(true);
                btn.SetActive(true);
                LayerManager.Instance.PrepareItems();
            }
            else
            {
                gameStatus = GameStatusType.Completed;
                Debug.LogError("1111111");
            }
        }
    }
    public void OnNewStartGame()
    {
        SceneManager.LoadScene("LoadScene");
    }
}
